<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Widgets for displaying the all public news stream.
 * 
 * According to what the explicit _News
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_newsstream.php';

require_once INSTALLDIR . '/widgets/slh_stream_micronews.php';
require_once INSTALLDIR . '/widgets/slh_stream_eventnews.php';
require_once INSTALLDIR . '/widgets/slh_stream_notenews.php';
require_once INSTALLDIR . '/widgets/slh_stream_photonews.php';

require_once INSTALLDIR . '/classes/News.php';


/**
 * Widget for displaying public news stream.
 */
class PublicNewsStream extends NewsStream
{
	/**
	 * Overrided.
	 * Returns a new stream item for the current sub news.
	 * 
	 * Distinguish the child type of the sub news and return related
	 * _NewsStreamItem!
	 * 
	 * @param $subnews, News instance.
	 */
	function newListItem(&$subnews)
	{
		// Distinguish.
		switch ($subnews->newstype) {
			case NEWS_NEWSTYPE_MICRONEWS: {
				$micronews = MicroNews::staticGet('news_id', $subnews->id);
				return new MicroNewsStreamItem($micronews, $this->out);
			}
			case NEWS_NEWSTYPE_NOTENEWS: {
				$notenews = NoteNews::staticGet('news_id', $subnews->id);
				return new NoteNewsStreamItem($notenews, $this->out);
				break;
			}
			case NEWS_NEWSTYPE_EVENTNEWS: {
				$eventnews = EventNews::staticGet('news_id', $subnews->id);
				return new EventNewsStreamItem($eventnews, $this->out);
				break;
			}
			case NEWS_NEWSTYPE_PHOTONEWS: {
				$photonews = PhotoNews::staticGet('news_id', $subnews->id);
				return new PhotoNewsStreamItem($photonews, $this->out);
				break;
			}
			default: {
				return null;
			}
		}
	}
}

?>